<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Societe
 *
 * @author Gael
 */
class Societe {
   public $id;
   public $nomsociete;
   
   
   
   function __construct($id, $nomsociete) {
       $this->id = $id;
       $this->nomsociete = $nomsociete;
   }
   public function getId() {
       return $this->id;
   }

   public function setId($id) {
       $this->id = $id;
   }

   public function getNomsociete() {
       return $this->nomsociete;
   }

   public function setNomsociete($nomsociete) {
       $this->nomsociete = $nomsociete;
   }

  static public function byId($id){
        try{
            $db= getPdo();
            $rep = $db->query("select * from societe where id=$id" );
            while($data =$rep->fetch()){
                $ta= new Societe($id, $data['$nomsociete']);
            }
            
            $rep->closeCursor();
            return $ta;
        }catch(Exception $e){
            die('erreur requete'.$e->getMessage());
            return false;
        }
    }
    static public function all(){
        try{
            $db= getPdo();
            $tab = array();
            
            $rep = $db->query("select * from societe  " );
            while($data =$rep->fetch()){
                $tab[$data['id']    ]=new Societe($data['id'], $data['nomsociete']);
                
            }
            $rep->closeCursor();
            return $tab;
        }catch(Exception $e){
            die('erreur requete'.$e->getMessage());
        }
    } 

   
   
}

?>
